package thread.producerAndconsumer;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 多个生产者和消费者模型(生产者一把梭，消费者一把梭)
 *
 * @author ganbo
 * @date 2022/10/29 10:18
 */
public class MyThreadPool {


}


class BlockingQueue<T> {

    //1: 任务队列（这里采用双向链表）
    private Deque<T> queue = new ArrayDeque<>();

    //2：锁
    private ReentrantLock lock = new ReentrantLock();

    //3：生产者条件变量
    private Condition fullWaitSet = lock.newCondition();

    //4: 消费者条件变量
    private Condition emptyWaitSet = lock.newCondition();

    //5：容量
    private int capacity;


    public BlockingQueue(int capacity) {
        this.capacity = capacity;
    }


    public static void main(String[] args) {
        Executors.newFixedThreadPool(8);

        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 3,
                200,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(3), new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                return new Thread("自定义线程池");
            }
        }, new ThreadPoolExecutor.AbortPolicy());
    }


}
